package ui;

import java.io.File;

import infrastructure.LoggingManager;

import org.apache.log4j.Logger;

import classification.ProteinPredictionResult;
import classification.ProteinPredictor;


public class ConsoleApp {

	private static Logger logger = LoggingManager.getLogger();
	
	
	public static void main(String[] args) {		
		option1(args);
		// Commented out for now. This is the option for multiple classifiers
		//option2(args);
	}
	
	/** THIS IS THE OPTION 1 :  A SINGLE CLASSIFIER
	 * @param args
	 */
	public static void option1(String[] args) {
		
		logger.info("----------STARTING OPTION 1---------");
		
		String fileNameModel = "config/classifierStefanos.model";		
		// This parameter is static. This must correlate with the model that we have defined.
		String fileNameTraining = "data/set2_17.arff";
		// This parameter is an INPUT
//		String fileNameTesting = "data/tmps.arff";
		
		String fileNameTesting = null;
		
		try {
			fileNameTesting = args[0];
			File file = new File(fileNameTesting);
			if (!file.exists()){
				System.out.println("The file you provided does not exist");
				System.exit(-1);
			}
		} catch(Exception ex) {
			logger.error(ex);
			System.out.println("Incorrect filename provided");
			System.exit(-1);
		}
		
		ProteinPredictor predictor = null;
		try {
			predictor = new ProteinPredictor(fileNameTraining, fileNameModel, fileNameTesting);
		} catch (Exception e1) {
			e1.printStackTrace();
			logger.error(e1);
			System.exit(-1);
		}
		
		ProteinPredictionResult result;
		try {
			result = predictor.classify();
			if (result == null)
				System.out.println("Classification could not be performed.");
			else {
//				System.out.println(result.getSummary());
				System.out.println(result.toString());
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e);
			System.exit(-1);
		}
			
		logger.info("----------EXITING OPTION 1---------");
	}
	
	
//	/** THIS IS THE OPTION 2 :  A SET OF THE 3 BEST CLASSIFIERS THAT WE HAVE BUILT
//	 * @param args
//	 */
//	public static void option2(String[] args) {
//		
//		logger.info("----------STARTING OPTION 2---------");
//		System.out.println("Welcome to Protein Prediction Project.");
//		String [] fileNameModels = new String[3];
//		
//		fileNameModels[1] = "config/classifierStefanos.model";
//		fileNameModels[0] = "config/classifierCaner.model";
//		fileNameModels[2] = "config/classifierDaniel.model";
//		
//		// This parameter is static. This must correlate with the model that we have defined.
//		String [] fileNameTraining = new String[3];
//		fileNameTraining[0] = "data/set1_17.arff";
//		fileNameTraining[1] = "data/set2_17.arff";
//		fileNameTraining[2] = "data/set3_17.arff";
//		
//		ProteinPredictorMultiple predictor = null;
//		try {
//			predictor = new ProteinPredictorMultiple(fileNameTraining, fileNameModels, fileNameTraining[0]);
//		} catch (Exception e1) {
//			e1.printStackTrace();
//			logger.error(e1);
//			System.exit(-1);
//		}
//		
//		ProteinPredictionResult result;
//		try {
//			// Test any set
//			result = predictor.classify();
//			if (result == null)
//				System.out.println("Classification could not be performed.");
//			else {
//				//System.out.println(result.getSummary());
//				System.out.println(result.toString());
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//			logger.error(e);
//			System.exit(-1);
//		}
//			
//		logger.info("----------EXITING OPTION 2---------");
//	}

}
